package com.lijiajia.cloud.authserver.pojo.mongodb;


import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.bson.types.ObjectId;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.mongodb.core.mapping.Document;

import java.time.LocalDateTime;
import java.util.Collections;
import java.util.Map;
import java.util.Set;

/**
 * 客户端
 */
@Data
@NoArgsConstructor
@Accessors(chain = true)
@Document(collection = "client")
public class Client {
    @Id
    @JsonIgnore
    private ObjectId mongodbId;

    /**
     * 客户端id
     */
    private String id;

    /**
     * 秘钥
     */
    @JsonIgnore
    private String secret;

    /**
     * 允许访问资源
     */
    private Set<String> resourceIds;

    /**
     * 授权类型
     */
    private Set<String> authorizedGrantTypes;

    /**
     * 范围
     */
    private Set<String> scope;

    /**
     * 自动审批范围
     */
    private Set<String> autoApproveScopes = Collections.emptySet();

    /**
     * 权限
     */
    private Set<String> authorities = Collections.emptySet();

    /**
     * 预定义重定向URI
     */
    private Set<String> redirectUris = Collections.emptySet();

    /**
     * 访问令牌有效期
     */
    private Integer accessTokenValiditySeconds;

    /**
     * 刷新令牌有效期
     */
    private Integer refreshTokenValiditySeconds;

    /**
     * 附加信息
     */
    private Map<String, Object> additionalInformation = Collections.emptyMap();

    /**
     * 创建时间
     */
    @CreatedDate
    private LocalDateTime createdAt;
    public static final String CREATED_AT = "created_at";
    /**
     * 最后修改时间
     */
    @LastModifiedDate
    private LocalDateTime lastModifiedAt;
    public static final String LAST_MODIFIED_AT = "last_modified_at";

    public static final String ID = "id";
    public static final String SECRET = "secret";
    public static final String RESOURCE_IDS = "resource_ids";
    public static final String AUTHORIZED_GRANT_TYPES = "authorized_grant_types";
    public static final String SCOPE = "scope";
    public static final String AUTO_APPROVE_SCOPES = "auto_approve_scopes";
    public static final String AUTHORITIES = "authorities";
    public static final String REDIRECT_URIS = "redirect_uris";
    public static final String ACCESS_TOKEN_VALIDITY_SECONDS = "access_token_validity_seconds";
    public static final String REFRESH_TOKEN_VALIDITY_SECONDS = "refresh_token_validity_seconds";
    public static final String ADDITIONAL_INFORMATION = "additional_information";
    public static final String CREATED_DATE = "created_date";
    public static final String LAST_MODIFIED_DATE = "last_modified_date";
}
